package com.yelobblog.yelobblog.service.impl;


import com.qiniu.util.Auth;
import com.yelobblog.yelobblog.domain.entity.qiniuBody;
import com.yelobblog.yelobblog.service.qiniuService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class qiniuServiceimpl implements qiniuService {
    @Value("${qiniu.accessKey}")
    private String accessKey;
    @Value("${qiniu.secretKey}")
    private String secretKey;
    @Value("${qiniu.bucket}")
    private String bucket;

    @Override
    public String uploadToken(String key) {
        Auth auth = Auth.create(accessKey, secretKey);
//        StringMap putPolicy = new StringMap();
//        putPolicy.put("callbackUrl", "http://blogback.yelob.vip/qiniu/callback");
//        putPolicy.put("callbackBody", "{\"key\":\"$(key)\"," +
//                "\"hash\":\"$(etag)\"," +
//                "\"bucket\":\"$(bucket)\"," +
//                "\"fsize\":$(fsize)}\","+
//                "\"userId\":\"$(x:userId)\"");
//        putPolicy.put("callbackBodyType", "application/json");
        long expireSeconds = 3600;
        return auth.uploadToken(bucket, key);
    }
    @Override
    public void callback(qiniuBody callbackBody) {
        // 在这里处理回调数据，例如保存到数据库
        System.out.println("Received callback: " + callbackBody);
    }
}
